<?php

namespace App\Http\Controllers\Api\Admin;

use Illuminate\Http\Request;
use App\Http\Resources\Api\Admin\AdminUsersResource;
use App\Http\Requests\Api\Admin\AdminUserUpdateRequest;
use App\Http\Requests\Api\Admin\AdminUserPsdRequest;
use App\Models\Admin\AdminUsers;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Api\Controller;

class AdminUserController extends Controller
{
    //返回单一用户信息
    public function show(User $user){
        return $this->success(new AdminUsersResource($user));
    }

    //更新用户信息
    public function update(AdminUserUpdateRequest $request)
    {
        $user = Auth::guard('admin')->user();
        $attributes = $request->only(['name', 'email', 'wechat', 'qq']);

        $user->update($attributes);

        return $this->success(new AdminUsersResource($user));
    }

    // 更新密码
    public function resetPsd(AdminUserPsdRequest $request)
    {
        $user = Auth::guard('admin')->user();
        $newPsd = $request->input('newPassword');

        $user->update(['password' => $newPsd]);

        return $this->success('更新密码成功');
    }
    //返回当前登录用户信息
    public function info(){
        $user = Auth::guard('admin')->user();
        return $this->success(new AdminUsersResource($user));
    }

}
